package cn.lili.modules.xiaotao;

import cn.lili.common.enums.ResultUtil;
import cn.lili.common.vo.ResultMessage;
import cn.lili.modules.goods.entity.dos.Goods;
import cn.lili.modules.goods.mapper.GoodsMapper;
import cn.lili.modules.system.entity.dos.Setting;
import cn.lili.modules.system.service.SettingService;
import com.alibaba.fastjson.JSONObject;
import org.apache.commons.compress.utils.Lists;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p></p>
 * @since 2023/4/10 23:17
 */
@Service
public class XtService {

	@Autowired
	private SettingService settingService;
	@Resource
	private GoodsMapper goodsMapper;
	public ResultMessage home(){
		Setting setting = settingService.get("BASE_SETTING");
		String settingValue = setting.getSettingValue();
		JSONObject json = JSONObject.parseObject(settingValue);
		String recommendImg = json.getString("recommendImg");
		String recommendTitle1 = json.getString("recommendTitle1");
		String recommendTitle2 = json.getString("recommendTitle2");
		String commonImg = json.getString("commonImg");
		String commonImgTitle1 = json.getString("commonImgTitle1");
		String commonImgTitle2 = json.getString("commonImgTitle2");

		List<Goods> goodsList = goodsMapper.getByPageShow();
		List<Goods> RECOMMEND = Lists.newArrayList();
		List<Goods> COMMON = Lists.newArrayList();
		for (Goods goods:goodsList
			 ) {
			if (goods.getPageShow().equals("RECOMMEND")){
				RECOMMEND.add(goods);
			}
			if (goods.getPageShow().equals("COMMON")){
				COMMON.add(goods);
			}
		}
		Map<String,Object> re = new HashMap<>();
		re.put("recommendImg",recommendImg);
		re.put("recommendTitle1",recommendTitle1);
		re.put("recommendTitle2",recommendTitle2);
		re.put("commonImg",commonImg);
		re.put("commonImgTitle1",commonImgTitle1);
		re.put("commonImgTitle2",commonImgTitle2);
		re.put("RECOMMEND",RECOMMEND);
		re.put("COMMON",COMMON);
		return ResultUtil.data(re);
	}
}
